<template>
  <div>
    <el-switch v-model="value1" />
    <el-button type="primary" v-if="value1" @click="add">添加</el-button>
  </div>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="date" label="Date" width="120">
      <template #default="scope">
        <template v-if="scope.row.id"> {{ scope.row.date }}</template>
        <template v-else>
          <el-input
            v-model="input"
            style="width: 240px"
            placeholder="Please input"
          />
        </template>
      </template>
    </el-table-column>
    <el-table-column prop="name" label="Name" width="100">
      <template #default="scope">
        <template v-if="scope.row.id"> {{ scope.row.date }}</template>
        <template v-else>
          <el-input
            v-model="input"
            style="width: 240px"
            placeholder="Please input"
          />
        </template>
      </template>
    </el-table-column>
    <el-table-column prop="address" label="Address">
      <template #default="scope">
        <template v-if="scope.row.id"> {{ scope.row.date }}</template>
        <template v-else>
          <el-input
            v-model="input"
            style="width: 240px"
            placeholder="Please input"
          />
        </template>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
const value1 = ref(false)
const tableData = ref([
  {
    id: 1,
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 2,
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 3,
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 4,
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
])
const add = () => {
  tableData.value.push({
    date: new Date(),
    name: '',
    address: '',
  })
}
</script>
